pPing = null
# forced：是否重新做身份验证
S.ping = (forced)->
    return pPing if pPing? and not forced

    pPing = S.api.get 'ping'
    $overlay = $(ST.AuthOverlay()).appendTo($('body'))
    pPing.then (res)->
        $overlay.remove()
        S.user = res
        S.trigger 'AuthChanged', res
    pPing.catch ->
        $overlay.remove()
        S.user = null
        S.trigger 'AuthChanged', false
    return pPing

$ ->
    S.on 'AuthChanged', -> console.log 'AuthChanged'

    # 验证身份
    pq = S.ping()
    pq.then S.toMe
    pq.catch S.showSignInDialog